﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Model.Config;

namespace Model.Entities_EF
{
    public partial class ICPrkmonitorContext : DbContext
    {
        private readonly MqttSettingsModel _mqttSettingsModel;

        public ICPrkmonitorContext(MqttSettingsModel mqttSettingsModel)
        {
            _mqttSettingsModel = mqttSettingsModel;
        }

        public ICPrkmonitorContext(DbContextOptions<ICPrkmonitorContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Tbhistory> Tbhistory { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseSqlServer(_mqttSettingsModel.SqlConnectionString);
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Tbhistory>(entity =>
            {
                entity.ToTable("tbhistory");

                entity.Property(e => e.Id)
                    .HasColumnName("ID")
                    .HasMaxLength(32)
                    .IsUnicode(false);

                entity.Property(e => e.DeviceName)
                    .HasMaxLength(255)
                    .IsUnicode(false);

                entity.Property(e => e.RecordTime).HasColumnType("datetime");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
